package controlLayer;
import modelLayer.*;


public class DvdCtrl {
    
    private DvdContainer dvdContainer;
    private Dvd dvd;
    
    public DvdCtrl() {
        dvdContainer = DvdContainer.getInstance();
    }
    
    public void createDvd(int barcode, String title, String artist, String publicationDate) {
        dvd = new Dvd(barcode, title, artist, publicationDate);
        dvdContainer.addDvd(dvd);
    }
    
    public Dvd findDvd(int barcode) {
        dvd = dvdContainer.findDvd(barcode);
        return dvd;
    }
    
    public void removeDvd(Dvd d) {
        dvdContainer.removeDvd(d);
    }
    
    public Copy findCopy(int serialNumber) {
        boolean found = false;
        int index = 0;
        while(index < dvd.copies.size() && !found) {
            Copy c = dvd.copies.get(index);
            if(c.getSerialNumber() == serialNumber) {
                found = true;
            }
            else {
                index++;
            }
        }
        
        if(found) {
            return dvd.copies.get(index);
        }
        else {
            return null;
        }
    }
    
    public void createCopy(int serialNumber, String purchaseDate, double purchasePrice) {
        Copy copy = new Copy(serialNumber, purchaseDate, purchasePrice);
        dvd.copies.add(copy);
        dvd.setCopiesNo(dvd.getCopiesNo()+1);
    }
    
    public void removeCopy(Copy copy) {
        dvd.copies.remove(copy);
    }
}
